var camelPoint=0;

$(document).ready(function(){

$(window).scrollTop(0);
$("html, body").animate({ scrollTop: 0 }, "fast");
	
	//set cemel moving 1000-1sec
	setInterval(camelMove,750)

	$('#forgot_pass_popup').load('appcamel/index.php?r=ajax/forgot_password');
	
	$('#push_button_section').load('appcamel/index.php?r=ajax/push_button');
	
	$('#login').load('appcamel/index.php?r=ajax/login');
	//, function() { jQuery('#mycarousel').jcarousel('reload'); };
	$('#choise_app').load('appcamel/index.php?r=ajax/choise_app', function() {
		jQuery('#mycarousel').jcarousel({
			wrap : 'circular'
		});
		add_active();
		$("#location_menu").change(function() {
			location_type_change();
		});
		location_type_change();
	}); 


  //placeholder for subjects
  $('.subject').each(function() {
  	 $(this).attr("placeholder", "Subject");
 	 $(this).focus(function(event){
       this.placeholder = '';
    	});
      $(this).blur(function(event){
       this.placeholder = 'Subject';
    	});
	});
	
	$('.subjdeluxe').each(function() {
  	 $(this).attr("placeholder", "Subject");
 	 $(this).focus(function(event){
       this.placeholder = '';
    	});
      $(this).blur(function(event){
       this.placeholder = 'Subject';
    	});
	});
   
   //placeholder for push messages
    $('.message').each(function() {
     $(this).attr("placeholder", "Your message");
 	 $(this).focus(function(event){
       this.placeholder = '';
    	});
      $(this).blur(function(event){
       this.placeholder = 'Your message';
    	});
	});
	
	//forgot password window
	$('#forgotpassword').on('click',function () {
		$('#passform').fadeIn(200);
				});
				
	$('#confirm_mail').on('click',function () {
		$('#passform').fadeOut(200);
				});
	
	$(document).mouseup(function (e) {
    var container = $("#passform");
    if (container.has(e.target).length === 0){
        container.fadeOut(200);
    }
});
	
});



function camelMove() { 
		$('#campbellfall').css('background-position',(-camelPoint*344+'px 0px'));
		if(camelPoint==0)
		{
			camelPoint=1;
		}
		else{
			camelPoint=0;
		}	
}

function login_check() {
	if ($('#login_alert').text().match("Hello")) 
	{
	login_sucess=1;
	$('#login').load('appcamel/index.php?r=ajax/login');
	$('#push_button_section').load('appcamel/index.php?r=ajax/push_button');
	$('#choise_app').load('appcamel/index.php?r=ajax/choise_app', function() { jQuery('#mycarousel').jcarousel({
    		wrap: 'circular'
    			});add_active(); });
   	$('#push_button').show();
		
	}
	else login_sucess=0;
	$('.login').val('');
	$('.password').val('');
}

/*----add class active to select application---*/
function add_active() {
$("#mycarousel img").click(function() {
	         $("#mycarousel img").removeClass("active");         
             $(this).toggleClass("active");
			 $("body").css("overflow","auto");
         });	
}


function updateChoiceApp(){
	$('#choise_app').load('appcamel/index.php?r=ajax/choise_app', function() {
		jQuery('#mycarousel').jcarousel({
			wrap : 'circular'
		});
		add_active();
		$("#location_menu").change(function() {
			location_type_change();
		});
		location_type_change();
	}); 
}

function location_type_change() {
	$('#One_point, #City, #Country, #Continent').hide();
	//console.log($('#location_menu').val());
	switch ($('#location_menu').val()) {
		case 'One_point':
			$('#One_point').show();
			break;
		case 'City':
			$('#City').show();
			break;
		case 'Country':
			$('#Country').show();
			break;
		case 'Continent':
			$('#Continent').show();
			break;
	}
} 
 

function setMessageType(messageType){
	$('#iph_msg_type').val(messageType);
}


 
 
function update_pre (os) {
if (os=='iphone') 

if ($('#iph_msg_type').val()=='base') $('#iphone_text_pre').html($('#Iphone_notification_content').val()); 
else 
{
	$('#iphone_text_pre').html($('#Iphone_rich_notification_subject').val()+tinyMCE.get('Iphone_rich_notification_content').getContent());
}
if (os=='android') $('#android_text_pre').html($('#Android_notification_subject').val()+'</BR>'+$('#Android_notification_content').val());
if (os=='blackberry') $('#blackberry_text_pre').html($('#Blackberry_notification_content').val());
} 

//============Confirm section ===================================================================

function confirm() {
$('#Iphone_rich_notification_content').val(tinyMCE.get('Iphone_rich_notification_content').getContent());
	serialize = $("#mainPushForm").serialize();
	//console.log(serialize);
	console.log(serialize);
	
	$.post('appcamel/index.php?r=ajax/confirm',serialize,function(result){
    //$('#login_alert').html(result);});
	//if(result.match("SUCCESS")) alert ("All ok.");
	//else alert ("Something wrong!");
	//console.log(result);
	console.log(result);
	push_sended_ok=result;
	switch (result)
	{
	case '1':
	$('#login_alert').text("All ok.");
	break;
	case '0':
	$('#login_alert').text("Please login.");
	break;
	default:
	//$('#login_alert').text(result);
	$('#login_alert').text("");
	}
	
	});
	
	
}
//============END Confirm section ===================================================================

